package va.radiomaria.gui;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionListener;
import java.util.HashMap;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SpringLayout;

import va.radiomaria.audio.Song;

public class UploadURLView  extends JDialog {

	private static final long serialVersionUID = 1L;
	private final JPanel contentPanel = new JPanel();
	private HashMap<String, JTextField> textFields = new HashMap<String, JTextField>();

	
	public UploadURLView(ActionListener controller) {
		setBounds(100, 100, 450, 300);
		getContentPane().setLayout(new BorderLayout());
		
		String[] labels = {"Artist", "Album", "Song", "Genre", "URL"};
		int numPairs = labels.length;

		//Create and populate the panel.
		JPanel p = new JPanel(new SpringLayout());
		for (int i = 0; i < numPairs; i++) {
		    JLabel l = new JLabel(labels[i] + ": ", JLabel.TRAILING);
		    p.add(l);
		    JTextField textField = new JTextField(10);
		    l.setLabelFor(textField);
		    p.add(textField);
		    textFields.put(labels[i], textField);
		}

		//Lay out the panel.
		SpringUtilities.makeCompactGrid(p,
		                                numPairs, 2, //rows, cols
		                                6, 6,        //initX, initY
		                                6, 6);       //xPad, yPad
		
		getContentPane().add(p, BorderLayout.CENTER);
		
		JPanel buttonPane = new JPanel();
		buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
		getContentPane().add(buttonPane, BorderLayout.SOUTH);
		{
			JButton okButton = new JButton("Ok");
			okButton.setActionCommand(CommonActionCommand.URL_CONFIRM.toString());
			okButton.addActionListener(controller);
			buttonPane.add(okButton);
			getRootPane().setDefaultButton(okButton);
		}
		{
			JButton cancelButton = new JButton("Cancel");
			cancelButton.setActionCommand(CommonActionCommand.URL_CANCEL.toString());
			cancelButton.addActionListener(controller);
			buttonPane.add(cancelButton);
		}
		getContentPane().add(buttonPane, BorderLayout.SOUTH);

		
	}
	
	public Song getSongInformation() {
		Song song = new Song(textFields.get("URL").getText());
		song.setAlbumTitle(textFields.get("Album").getText());
		song.setArtist(textFields.get("Artist").getText());
		song.setSongTitle(textFields.get("Song").getText());
		song.setGenre(textFields.get("Genre").getText());
		return song;
	}

}
